/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author HP
 */
@Entity
@Table(name = "spot")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Spot.findAll", query = "SELECT s FROM Spot s"),
    @NamedQuery(name = "Spot.findBySid", query = "SELECT s FROM Spot s WHERE s.sid = :sid"),
    @NamedQuery(name = "Spot.findByName", query = "SELECT s FROM Spot s WHERE s.name = :name"),
    @NamedQuery(name = "Spot.findByPic", query = "SELECT s FROM Spot s WHERE s.pic = :pic")})
public class Spot implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @NotNull
    @Column(name = "sid")
    private Integer sid;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 255)
    @Column(name = "name")
    private String name;
    @Size(max = 255)
    @Column(name = "pic")
    private String pic;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "sid")
    private Collection<Comment> commentCollection;
    @JoinColumn(name = "rid", referencedColumnName = "rid")
    @ManyToOne(optional = false)
    private Restaurant rid;
    @JoinColumn(name = "username", referencedColumnName = "username")
    @ManyToOne(optional = false)
    private User username;

    public Spot() {
    }

    public Spot(Integer sid) {
        this.sid = sid;
    }

    public Spot(Integer sid, String name) {
        this.sid = sid;
        this.name = name;
    }

    public Integer getSid() {
        return sid;
    }

    public void setSid(Integer sid) {
        this.sid = sid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPic() {
        return pic;
    }

    public void setPic(String pic) {
        this.pic = pic;
    }

    @XmlTransient
    public Collection<Comment> getCommentCollection() {
        return commentCollection;
    }

    public void setCommentCollection(Collection<Comment> commentCollection) {
        this.commentCollection = commentCollection;
    }

    public Restaurant getRid() {
        return rid;
    }

    public void setRid(Restaurant rid) {
        this.rid = rid;
    }

    public User getUsername() {
        return username;
    }

    public void setUsername(User username) {
        this.username = username;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (sid != null ? sid.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Spot)) {
            return false;
        }
        Spot other = (Spot) object;
        if ((this.sid == null && other.sid != null) || (this.sid != null && !this.sid.equals(other.sid))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entities.Spot[ sid=" + sid + " ]";
    }
    
}
